package core.semantics.util;

import java.util.List;

import core.types.SimpleType;

public class Procedure extends ElementDefinition {

	private SimpleType returnType;
	private List<Variable> parameters;

	public Procedure(String name, List<Variable> parameters,
			SimpleType returnType, int line, int column) {
		super(name, line, column);

		this.parameters = parameters;
		this.returnType = returnType;
	}

	public Procedure(List<Variable> parameters, SimpleType returnType,
			ElementDefinition eDefinition) {
		super(eDefinition);

		this.parameters = parameters;
		this.returnType = returnType;
	}

	public SimpleType getReturnType() {
		return returnType;
	}

	public List<Variable> getParameters() {
		return parameters;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Procedure)) {
			return false;
		}

		Procedure other = (Procedure) obj;

		return super.equals(other)
				&& this.parameters.size() == other.parameters.size()
				&& areEquals(this.parameters, other.parameters);
	}
	
	private boolean areEquals(List<Variable> theseVars, List<Variable> thoseVars) {
		for (int iVar = 0; iVar < theseVars.size(); iVar++) {
			if (!theseVars.get(iVar).getType().equals(thoseVars.get(iVar).getType())) {
				return false;
			}
		}
		
		return true;
	}

}
